package com.sun.until;

import cn.hutool.json.JSONUtil;
import com.sun.entity.User;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;

@Component
public class UserUntil {

    public static User getUserBySession(HttpSession session) {
        String userStr = (String) session.getAttribute("user");
        return JSONUtil.toBean(userStr, User.class);
    }

    public static void setUserBySession(HttpSession session, User user) {
        String jsonStr = JSONUtil.toJsonStr(user);
        session.setAttribute("user", jsonStr);
    }
}
